package demo.java.parallelprogram.masterworker;

import java.util.Map;
import java.util.Queue;

public class Worker implements Runnable {
	
	protected Queue<Object> workQueue;//任务队列，用于取得子任务
	
	protected Map<String,Object> resultMap;//子任务处理结果集
	
	//子任务处理的逻辑，在子类中实现具体逻辑
	public Object handel(Object input){
		return input;
	}

	@Override
	public void run() {
		while(true){
			Object input  = workQueue.poll();
			if(input == null){
				break;
			}
			
			Object re=handel(input);
			resultMap.put(Integer.toString(input.hashCode()), re);
		}
	}

	public Map<String, Object> getResultMap() {
		return resultMap;
	}

	public void setResultMap(Map<String, Object> resultMap) {
		this.resultMap = resultMap;
	}
	
}
